﻿using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "Flock/Behavior/Composite")]
public class CompositeBehavior : FlockBehavior
{
    public FlockBehavior[] behaviors;
    public float[] weights;

    public override Vector2 Force(FlockItem item, List<Transform> context)
    {
        if (weights.Length != behaviors.Length)
        {
            Debug.LogError("Data mismatch in " + name, this);
            return Vector2.zero;
        }

        Vector2 force = Vector2.zero;

        for (int i = 0; i < behaviors.Length; i++)
        {
            float weight = weights[i];
            Vector2 partialForce = behaviors[i].Force(item, context) * weight;
            force += partialForce;
        }

        return force;
    }
}
